/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JFreeChartExtensions.chartextensions.serieshandler;

import JFreeChartExtensions.chartextensions.AbstractChartPanelExtension;
import JFreeChartExtensions.ExtendableChartPanel;
import JFreeChartExtensions.JChartMenu.ChartMenuListeners.RemoveSeriesDialogListener;
import JFreeChartExtensions.JChartMenu.JChartMenu;
import org.jfree.chart.ChartPanel;

/**
 *
 * @author Nobody
 */
public class DynamicallyAddingAndRemovingSeriesExtension extends AbstractChartPanelExtension {
 
    private JChartMenu addRemoveSeriesMenuItem;


    public DynamicallyAddingAndRemovingSeriesExtension(ExtendableChartPanel panel) {
        super(panel);
        name = "SeriesManipulationExtension";
     
    }

    @Override
    public void applyExtension(ChartPanel chartPanel) {
        this.chartPanel = (ExtendableChartPanel) chartPanel;
        addRemoveSeriesMenuItem = new JChartMenu("Add/Remove series");
        addRemoveSeriesMenuItem.addListener(new RemoveSeriesDialogListener((ExtendableChartPanel) chartPanel));
        chartPanel.getPopupMenu().add(addRemoveSeriesMenuItem);
    }

    @Override
    public void removeExtension() {
        chartPanel.getPopupMenu().remove(addRemoveSeriesMenuItem);
    }

}
